#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

class Solution{
    public:
    //my ans -->out of time
    vector<int> ans1(vector<int>& numbers, int target){
        int p_l = 0, p_r = 1;
        int lenght = numbers.size();
        int temp;
        vector<int> out;
        while(p_r < lenght){
            temp = target - numbers[p_l];
            while(p_r < lenght){
                if(numbers[p_r] == temp){
                    out.push_back(p_l+1);
                    out.push_back(p_r+1);
                    break;
                }
                p_r++;
            }
            p_l++;
            p_r = p_l + 1;
        }
        return out;
    }

    vector<int> ans2(vector<int>& numbers, int target){
        int lenght = numbers.size();
        int p_l = 0, p_r = lenght - 1;
        int temp;
        vector<int> out;
        while(p_l < p_r){
            temp = numbers[p_l] + numbers[p_r];
            if(temp > target){
                p_r--;
            }else if(temp < target){
                p_l++;
            }else{
                out.push_back(p_l + 1);
                out.push_back(p_r + 1);
                return out;
            }
        }
        return {-1, -1};
    }

};

void test1(){
    Solution s;
    vector<int> numbers = {2, 7, 11, 15};
    int target = 9;
    // vector<int> ret = s.ans1(numbers, target);
    vector<int> ret = s.ans2(numbers, target);
    cout << "[" << ret[0] << ", " << ret[1] << "]" << endl;
}

void test2(){
    Solution s;
    vector<int> numbers = {2,3,4};
    int target = 6;
    // vector<int> ret = s.ans1(numbers, target);
    vector<int> ret = s.ans2(numbers, target);
    cout << "[" << ret[0] << ", " << ret[1] << "]" << endl;
}

void test3(){
    Solution s;
    vector<int> numbers = {-1,0};
    int target = -1;
    // vector<int> ret = s.ans1(numbers, target);
    vector<int> ret = s.ans2(numbers, target);
    cout << "[" << ret[0] << ", " << ret[1] << "]" << endl;
}


int main(void){
    test1();
    test2();
    test3();

    return 0;
}